package de.cachaca.lildancefreak;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import de.cachaca.lildancefreak.pierre.CalculatorImplPierre;
import de.cachaca.lildancefreak.valerie.CalculatorImplValerie;

public class CalculatorTest {
	
	private Calculator calculator;

	@Before
	public void setup() {
//		calculator = new CalculatorImplPierre(1.0);
		calculator = new CalculatorImplValerie(1.0);
	}
	
	@Test
	public void testDefaultConstructor() {
		Assert.assertEquals(0.0, new CalculatorImplValerie().getResult(), 0.01);
	}
	
	@Test
	public void testInitConstructor() {
		Assert.assertEquals(1.0, calculator.getResult(), 0.01);
	}
	
	@Test
	public void testAdd() {
		calculator.add(2.9);
		calculator.add(5.0);
		calculator.add(-2.9);
		Assert.assertTrue(calculator.isValuePositive());
		Assert.assertEquals(6.0, calculator.getResult(), 0.01);
	}
	
	@Test
	public void testSubtract() {
		calculator.subtract(2.9);
		calculator.subtract(5.0);
		calculator.subtract(-2.9);
		Assert.assertFalse(calculator.isValuePositive());
		Assert.assertEquals(-4.0, calculator.getResult(), 0.01);
	}
	
	@Test
	public void testMultiply() {
		calculator.multiply(2.0);
		calculator.multiply(5.0);
		Assert.assertTrue(calculator.isValuePositive());
		Assert.assertEquals(10.0, calculator.getResult(), 0.01);
	}
	
	@Test
	public void testMultiplyWith0() {
		calculator.multiply(0.0);
		Assert.assertEquals(0.0, calculator.getResult(), 0.01);
	}
	
	@Test
	public void testReset() {
		calculator.reset(0.0);
		Assert.assertTrue(calculator.isValuePositive());
		Assert.assertEquals(0.0, calculator.getResult(), 0.01);
		
		calculator.multiply(1000.0);
		Assert.assertTrue(calculator.isValuePositive());
		Assert.assertEquals(0.0, calculator.getResult(), 0.01);
	}
	
}
